﻿using Application.PositionService;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.In;
using Domain.Entity.search;
using Domain.Entity.zct;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Instock_hService
{
    public class Instock_hService : IInstock_hService
    {
        private readonly IInstock_hRepository instock_HRepository;
        private readonly IMapper mapper;

        public Instock_hService(IInstock_hRepository instock_HRepository,IMapper mapper)
        {
            this.instock_HRepository = instock_HRepository;
            this.mapper = mapper;
        }

        //添加入库单
        public async Task<int> AddInstock_h(AddInstock_hDto addInstock_HDto)
        {
            Instock_h instock_H= mapper.Map<Instock_h>(addInstock_HDto);
            return await instock_HRepository.AddInstock_h(instock_H);
        }


        //删除入库单
        public async Task<int> DeleteInstock_h(int id)
        {
            return await instock_HRepository.DeleteInstock_h(id);
        }

        //高级查询
        public async Task<FenYe<Instock_h>> GetAdvancedInstock_h(FenYe<Instock_h> fenYe, string? code, string? starttotal, string? endtotal, string? startdate, string? enddate, string? startnum, string? endnum, int? status, string? type, int? whid, string? createname, string? startcreatetime, string? endcreatetime, string? approvername, string? startapprovertime, string? endapprovertime, string? inuser, string? inorder)
        {
            return await instock_HRepository.GetAdvancedInstock_h(fenYe, code, starttotal, endtotal, startdate, enddate, startnum, endnum, status, type, whid, createname, startcreatetime, endcreatetime, approvername, startapprovertime, endapprovertime, inuser, inorder);
        }


        //根据货品id查询入库记录
        public async Task<List<Instock_h>> GetAllInstock_h(int procid)
        {
            return await instock_HRepository.GetAllInstock_h(procid);
        }


        //根据关联单号查询入库记录
        public async Task<List<Instock_h>> GetAllInstock_hByCode(string code)
        {
            return await instock_HRepository.GetAllInstock_hByCode(code);
        }

        //分页查询
        public async Task<FenYe<Instock_h>> GetInstock_h(FenYe<Instock_h> fenYe, string? code, string? type, int? status, int? whid)
        {
            return await instock_HRepository.GetInstock_h(fenYe, code, type, status, whid);
        }

        //根据id查询入库单
        public async Task<Instock_h> GetInstock_hById(int instockid)
        {
            return await instock_HRepository.GetInstock_hById(instockid);
        }

        //客户id查
        public async Task<FenYe<Instock_h>> GetInstock_hCust(FenYe<Instock_h> fenYe, int cust_id)
        {
            return await instock_HRepository.GetInstock_hCust(fenYe,cust_id);
        }

        //供应商id查
        public async Task<FenYe<Instock_h>> GetInstock_hSup(FenYe<Instock_h> fenYe, int sup_id)
        {
            return await instock_HRepository.GetInstock_hSup(fenYe,sup_id);
        }

        //入库统计
        public async Task<Instock_hTJResult> Instock_hTJ(string? timeType, string? code, int? whid, string? instarttime, string? inendtime, string? starttime, string? endtime, string inType, int? page, int? pagesize)
        {
            return await instock_HRepository.Instock_hTJ(timeType, code, whid, instarttime, inendtime, starttime, endtime, inType, page,pagesize);
        }


        //修改入库单
        public async Task<int> UpdateInstock_h(UpdateInstock_hDto updateInstock_HDto)
        {
            Instock_h instock_H=mapper.Map<Instock_h>(updateInstock_HDto);
            return await instock_HRepository.UpdateInstock_h(instock_H);
        }


        //修改单据状态
        public async Task<int> UpdateStatus(int instockid, int status, string approvername, string approvertime)
        {
            return await instock_HRepository.UpdateStatus(instockid, status, approvername, approvertime);
        }


        //修改状态
        public async Task<int> UpdateStatus(int instockid, int status)
        {
            return await instock_HRepository.UpdateStatus(instockid,status);
        }
    }
}
